var xiGua = require("../app/xiGua/watchVideo");
var daiShuDD = require("../app/daiShuDD/watchVideo");
var hongGuoMF = require("../app/hongGuoMF/watchVideo");
var { gUtils, deviceUtils, appUtils } = require("../utils");

function watch(fn, span) {
  var index = 0;
  var startTime = Date.now();
  span = (span || 10) * 60;
  while (true) {
    var hasExec = gUtils.hasExec(startTime);
    if (hasExec >= span) {
      return;
    }
    fn(index++);
  }
}

function main(appName, span) {
  if (appName && appName.indexOf("西瓜") != -1) {
    watch(function (index) {
      xiGua.watchVideo(index);
    }, span);
  } else if (appName && appName.indexOf("袋鼠") != -1) {
    watch(function (index) {
      daiShuDD.watchVideo(index);
    }, span);
  } else if (appName && appName.indexOf("红果") != -1) {
    watch(function (index) {
      hongGuoMF.watchVideo(index);
    }, span);
  }
}
Wang.main = main;
